package com.liqi.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.liqi.common.annotation.Log;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.enums.BusinessType;
import com.liqi.info.domain.TInfoPublicity;
import com.liqi.info.service.ITInfoPublicityService;
import com.liqi.common.utils.poi.ExcelUtil;
import com.liqi.common.core.page.TableDataInfo;

/**
 * 公示Controller
 * 
 * @author xiaoli
 * @date 2022-11-19
 */
@RestController
@RequestMapping("/info/publicity")
public class TInfoPublicityController extends BaseController
{
    @Autowired
    private ITInfoPublicityService tInfoPublicityService;

    /**
     * 查询公示列表
     */
    @PreAuthorize("@ss.hasPermi('info:publicity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInfoPublicity tInfoPublicity)
    {
        startPage();
        List<TInfoPublicity> list = tInfoPublicityService.selectTInfoPublicityList(tInfoPublicity);
        return getDataTable(list);
    }

    /**
     * 导出公示列表
     */
    @PreAuthorize("@ss.hasPermi('info:publicity:export')")
    @Log(title = "公示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInfoPublicity tInfoPublicity)
    {
        List<TInfoPublicity> list = tInfoPublicityService.selectTInfoPublicityList(tInfoPublicity);
        ExcelUtil<TInfoPublicity> util = new ExcelUtil<TInfoPublicity>(TInfoPublicity.class);
        util.exportExcel(response, list, "公示数据");
    }

    /**
     * 获取公示详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:publicity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tInfoPublicityService.selectTInfoPublicityById(id));
    }

    /**
     * 新增公示
     */
    @PreAuthorize("@ss.hasPermi('info:publicity:add')")
    @Log(title = "公示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInfoPublicity tInfoPublicity)
    {
        tInfoPublicity.setCreateUserId(getUserId().toString());
        tInfoPublicity.setDeptId(getDeptId().toString());
        tInfoPublicity.setCreateBy(getUsername());
        tInfoPublicity.setUpdateBy(getUsername());
        return toAjax(tInfoPublicityService.insertTInfoPublicity(tInfoPublicity));
    }

    /**
     * 修改公示
     */
    @PreAuthorize("@ss.hasPermi('info:publicity:edit')")
    @Log(title = "公示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInfoPublicity tInfoPublicity)
    {
        return toAjax(tInfoPublicityService.updateTInfoPublicity(tInfoPublicity));
    }

    /**
     * 删除公示
     */
    @PreAuthorize("@ss.hasPermi('info:publicity:remove')")
    @Log(title = "公示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInfoPublicityService.deleteTInfoPublicityByIds(ids));
    }
}
